package com.gogowan.agroenterprise;

import com.gogowan.agroenterprise.base.BaseActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.TextView;

/**
 * type = 1:起始码、结束码拍码类型选择 type = 2:拍照类型选择 type = 3:摄像类型选择
 * */
public class PaiMaTypeMoreActivity extends BaseActivity implements
		OnClickListener {

	private TextView cameraBtn, inputBtn, cancelBtn;
	private int type;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_paima_type);
		type = getIntent().getIntExtra("type", -1);
		this.overridePendingTransition(R.anim.bottom_in, R.anim.bottom_out);

		WindowManager m = getWindowManager();
		Display d = m.getDefaultDisplay(); // 为获取屏幕宽、高

		LayoutParams p = getWindow().getAttributes(); // 获取对话框当前的参数值
		getWindow().setGravity(Gravity.LEFT | Gravity.BOTTOM);
		p.x = 0; // 新位置X坐标
		p.y = 0; // 新位置Y坐标
		// p.height = (int) (d.getHeight() * 0.3); // 高度设置为屏幕的1.0
		p.width = (int) (d.getWidth()); // 宽度设置为屏幕的宽度
		// p.alpha = 1.0f; // 设置本身透明度
		// p.dimAmount = 1.5f; //设置黑暗度

		getWindow().setAttributes(p); // 设置生效

		initView();

	}

	private void initView() {

		cameraBtn = (TextView) findViewById(R.id.paima_type_cameraBtn);
		inputBtn = (TextView) findViewById(R.id.paima_type_inputBtn);
		cancelBtn = (TextView) findViewById(R.id.paima_type_cancelBtn);
		if (type == 2) {
			// 拍照类型选择
			cameraBtn.setText("拍照");
			inputBtn.setText("从手机相册选择");
		} else if (type == 3) {
			// 摄像类型选择
			cameraBtn.setText("摄像");
			inputBtn.setText("从本地视频选择");
		}
		cameraBtn.setOnClickListener(this);
		inputBtn.setOnClickListener(this);
		cancelBtn.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent intent;
		switch (v.getId()) {
		case R.id.paima_type_cameraBtn: // 拍产品码

			intent = new Intent();
			setResult(1, intent);
			this.finish();
			this.overridePendingTransition(R.anim.bottom_out1,
					R.anim.bottom_in1);
			break;

		case R.id.paima_type_inputBtn: // 输产品码
			intent = new Intent();
			setResult(2, intent);
			this.finish();
			this.overridePendingTransition(R.anim.bottom_out1,
					R.anim.bottom_in1);
			break;
		case R.id.paima_type_cancelBtn: // 取消
			intent = new Intent();
			this.finish();
			this.overridePendingTransition(R.anim.bottom_out1,
					R.anim.bottom_in1);
			break;
		default:
			break;
		}
	}

	// 实现onTouchEvent触屏函数但点击屏幕时销毁本Activity
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		this.finish();
		this.overridePendingTransition(R.anim.bottom_out1, R.anim.bottom_in1);
		return true;
	}

	/**
	 * 返回
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK)// 返回键
		{
			this.finish();
			this.overridePendingTransition(R.anim.bottom_out1,
					R.anim.bottom_in1);
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

}
